﻿using System;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;
using Microsoft.Win32;
using Resn.WhuPub.BLL;

namespace Resn.WhuPub.WPFClientUI
{
        /// <summary>
        /// ManageExamineePage.xaml 的交互逻辑
        /// </summary>
        public partial class ManageMajorsPage : Page
        {
                private readonly GlobalManager _gm = GlobalManager.Instance;

                public ManageMajorsPage()
                {
                        InitializeComponent();
                }

                private void Page_Loaded(object sender, RoutedEventArgs e)
                {
                        if (_gm.LoginEmployee == null)
                        {
                                MessageBox.Show("请先登录系统");
                                NavigationService.Navigate(new Uri("StartPage.xaml", UriKind.Relative));
                        }
                        LayoutRoot.DataContext = _gm;
                }

                private void CreateButton_Click(object sender, RoutedEventArgs e)
                {
                        NavigationService.Navigate(new Uri("CreateMajorPage.xaml", UriKind.Relative));
                }

                private void UpdateButton_Click(object sender, RoutedEventArgs e)
                {
                        if (_gm.Major == null)
                        {
                                MessageBox.Show("请选择要编辑的门类");
                                return;
                        }

                        NavigationService.Navigate(new Uri("UpdateMajorWindow.xaml", UriKind.Relative));
                }

                private void DeleteButton_Click(object sender, RoutedEventArgs e)
                {
                        // 在此处新建事件处理程序实现。
                        if (_gm.Major == null)
                        {
                                MessageBox.Show("请选择要删除的门类");
                                return;
                        }

                        if (
                                MessageBox.Show("确定要删除" + _gm.Major.Name + "吗？",
                                                "警告", MessageBoxButton.YesNo) == MessageBoxResult.Yes)
                        {
                                _gm.Major.Delete();
                                _gm.Major = null;

                                //gm.Majors = _gm.Subject.Majors;
                                NavigationService.Refresh();
                        }
                }

                private void SearchButton_Click(object sender, RoutedEventArgs e)
                {
                        NavigationService.Navigate(new Uri("SearchMajorPage.xaml", UriKind.Relative));
                }
        }
}